/**
 * @ClassName LC299
 * 猜数字游戏
 * @Author ykx
 * @Date 2024/3/10 10:40
 * @Version 1.0
 */
public class LC299 {
    public static void main(String[] args) {
        LC299 lc299 = new LC299();
        System.out.println(lc299.getHint("01", "11"));
    }

    private String getHint(String secret, String guess) {
        int countA = 0;
        int countB = 0;
        if (secret.length() != guess.length()) {
            return "";
        }

        StringBuilder secretBuilder = new StringBuilder(secret);
        StringBuilder guessBuilder = new StringBuilder(guess);


        for (int i = 0; i < secretBuilder.length(); i++) {
            if (guessBuilder.charAt(i) == secretBuilder.charAt(i)) {
                countA++;
                secretBuilder.deleteCharAt(i);
                guessBuilder.deleteCharAt(i);
                i--;
            }
        }

        for (int i = 0; i < guessBuilder.length(); i++) {
            Character c = guessBuilder.charAt(i);
            if (secretBuilder.indexOf(String.valueOf(c)) != -1) {
                countB++;
                guessBuilder.deleteCharAt(i);
                secretBuilder.deleteCharAt(secretBuilder.indexOf(String.valueOf(c)));
                i--;
            }
        }

        return countA + "A" + countB + "B";
    }
}
